<template>
    <div class="index">
        <!-- 头部导航栏 -->
        <div class="head">
            <h3>食谱秀网</h3>
            <svg class="icon icon-caidan" aria-hidden="true" @click="show = !show">
                <use xlink:href="#icon-caidan"></use>
            </svg>
            <!-- 头部隐藏栏 -->
            <transition name="fade">
                <ul class="tab" v-if="!show">
                    <router-link to="/index">
                        <li>
                            <span>
                                <svg class="icon" aria-hidden="true">
                                    <use xlink:href="#icon-icons_statistics"></use>
                                </svg>
                                首页
                            </span>
                        </li>
                    </router-link>
                    <router-link to="/classify">
                        <li>
                            <span>
                                <svg class="icon" aria-hidden="true">
                                    <use xlink:href="#icon-tag"></use>
                                </svg>
                                食材分类
                            </span>
                        </li>
                    </router-link>
                    <router-link to="/Cookbook">
                        <li>
                            <span>
                                <svg class="icon" aria-hidden="true">
                                    <use xlink:href="#icon-tag"></use>
                                </svg>
                                菜谱大全
                            </span>
                        </li>
                    </router-link>
                    <router-link to="/HomeCooked">
                        <li>
                            <span>
                                <svg class="icon" aria-hidden="true">
                                    <use xlink:href="#icon-tag"></use>
                                </svg>
                                家常菜谱
                            </span>
                        </li>
                    </router-link>
                    <router-link to="/restriction">
                        <li>
                            <span>
                                <svg class="icon" aria-hidden="true">
                                    <use xlink:href="#icon-star"></use>
                                </svg>
                                食物相克
                            </span>
                        </li>
                    </router-link>
                    <router-link to="/PregnantDiet">
                        <li>
                            <span>
                                <svg class="icon" aria-hidden="true">
                                    <use xlink:href="#icon-tag"></use>
                                </svg>
                                孕妇食谱
                            </span>
                        </li>
                    </router-link>
                    <router-link to="/FoodInformation">
                        <li>
                            <span>
                                <svg class="icon" aria-hidden="true">
                                    <use xlink:href="#icon-tag"></use>
                                </svg>
                                美食资讯
                            </span>
                        </li>
                    </router-link>
                </ul>
            </transition>
            <!-- 侧边栏 -->
            <div class="aside">
                <div class="phone" v-show="true">
                    <router-link  to="/appdownloads">
                        <img src="../../assets/images/QR code/float-icon3.png" alt="">
                    </router-link>
                </div>
                <div class="up" @click="backTop" v-show="backTopShow">
                    <img src="../../assets/images/QR code/float-icon1.png" alt="">
                </div>
            </div>
        </div>
        <!-- 轮播图 -->
        <mt-swipe :auto="4000" :show-indicators="false">
            <mt-swipe-item>
                <img src="../../assets/images/index/banner4.jpg" alt="">
                <span>
                    <p class="fenshu">1 / 3</p>
                </span>
            </mt-swipe-item>
            <mt-swipe-item>
                <img src="../../assets/images/index/banner1.jpg" alt="">
                <span>
                    <p class="fenshu">2 / 3</p>
                </span>
            </mt-swipe-item>
            <mt-swipe-item>
                <img src="../../assets/images/index/1510473439658_4.jpg" alt="">
                <span>
                    <p class="fenshu">3 / 3</p>
                    <p class="left">羊肉怎样去除膻味</p>
                </span>
            </mt-swipe-item>
        </mt-swipe>
        <!-- 搜索 -->
        <div class="sousuo">
            <svg class="icon icon-fangdajing" aria-hidden="true">
                <use xlink:href="#icon-fangdajing1"></use>
            </svg>
            <input type="text" class="sousuo1" placeholder="请输入关键字例:红烧排骨">
            <router-link to="/search">
                <input type="submit"  class="sousuo2" value="搜索">
            </router-link>
        </div>
        <!-- 分类部分 -->
        <ul class="clasify"> 
            <router-link to="/dishes">
                <li style="background: #fd5f5e;">
                    <span class="tags">
                        <svg class="icon" aria-hidden="true">
                            <use xlink:href="#icon-meishi2"></use>
                        </svg>
                    </span>
                    <p style="left:7px">家常菜</p>
                </li>
            </router-link>
            <router-link to="/noodles">
                <li style="background: #fb582f;">
                    <span>
                        <svg class="icon" aria-hidden="true">
                            <use xlink:href="#icon-mianshi"></use>
                        </svg>
                    </span>
                    <p style="left:13px">面食</p>
                </li>
            </router-link>
            <router-link to="/dishes">
                <li style="background: #7068e2;">
                    <span>
                        <svg class="icon" aria-hidden="true">
                            <use xlink:href="#icon-wandou"></use>
                        </svg>
                    </span>
                    <p style="left:13px">烘焙</p>
                </li>
            </router-link>
            <router-link to="/noodles">
                <li style="background: #4ca4fe;">
                    <span>
                        <svg class="icon" aria-hidden="true">
                            <use xlink:href="#icon-zaocan"></use>
                        </svg>
                    </span>
                    <p style="left:13px">早餐</p>
                </li>
            </router-link>
            <router-link to="/Cookbook">
                <li style="background: #ffce34;">
                    <span>
                        <svg class="icon" aria-hidden="true">
                            <use xlink:href="#icon-meishi2"></use>
                        </svg>
                    </span>
                    <p>菜谱大全</p>
                </li>
            </router-link>
            <router-link to="/classify">
                <li style="background: #33d197;">
                    <span>
                        <svg class="icon" aria-hidden="true">
                            <use xlink:href="#icon-wandou-copy"></use>
                        </svg>
                    </span>
                    <p style="left:13px">食材</p>
                </li>
            </router-link>
            <router-link to="/dishes">
                <li style="background: #4ca4fe;">
                    <span>
                        <svg class="icon" aria-hidden="true">
                            <use xlink:href="#icon-shutiao1"></use>
                        </svg>
                    </span>
                    <p style="left:13px">零食</p>
                </li>
            </router-link>
            <router-link to="/categories">
                <li style="background: #ff6d56;">
                    <span>
                        <svg class="icon" aria-hidden="true">
                            <use xlink:href="#icon-leimupinleifenleileibie"></use>
                        </svg>
                    </span>
                    <p>全部分类</p>
                </li>
            </router-link>
        </ul>
        <!-- 菜谱热搜榜 -->
        <h3 class="title">菜谱热搜榜</h3>
        <ul class="food">
            <li v-for="(item,index) in search" :key="index">
                <router-link to="/BraisedPork">
                    <p>{{item}}</p>
                </router-link>
            </li>
        </ul>
        <!-- 最新食谱 -->
        <h3 class="title">最新食谱</h3>
        <ul class="foods">
            <li v-for="(item,index) in recipe" :key="index">
                <router-link to="/spicy">
                    <img :src="item.src" alt="">
                    <p>{{item.dish}}</p>
                </router-link>
            </li>
        </ul>
        <!-- 时令与热门 -->
        <h3 class="title">时令与热门</h3>
        <ul class="hot">
            <li v-for="(item,index) in hot" :key="index">
                <router-link to="/BraisedPork">
                    <p>{{item}}</p>
                </router-link>
            </li>
        </ul>
        <!-- 推荐阅读 -->
        <h3 class="title read" style="color: red;padding-top: 5px;">推荐阅读</h3>
        <ul class="reading">
            <li v-for="(item,index) in reading.slice(0,10)" :key="index">
                <router-link to="/reading">
                    <img :src="item.src" alt="">
                    <h4>{{item.title}}</h4>
                    <p>{{item.content}}
                        <span>{{item.date}}</span>
                    </p>
                </router-link>
            </li>
        </ul>
        <!-- 底部  -->
        <div class="bottom">
            <div class="wu">没有更多数据</div>
        </div>
        <div class="foot">
            Copyright 食谱秀 m.shipuxiu.com <br>
            <p> 官方微信号: <span style="color: #ff0000;">chaoliu1588 </span>
                 
                <router-link to="https://m.shipuxiu.com/fenlei/">食谱分类</router-link>
                <router-link to="https://support.qq.com/products/113359/">我要吐槽</router-link>
                <router-link to="https://new.cnzz.com/v1/login.php?siteid=5433565">站长统计 </router-link>
             </p> 
        </div>
    </div>
</template>

<script>
export default {
    data(){
        return {
            search:[],
            hot:[],
            recipe:[],
            reading:[],
            show:true,
            backTopShow:false
        }
    },
    mounted(){
        // 获取数据
        this.$http.get('../../data/data.json')
        .then((response)=> {
            this.recipe = response.data.recipe
            this.search = response.data.search
            this.hot = response.data.hot
            this.reading = response.data.reading
        })
        .catch(function (error) {
            console.log(error);
        })
        .then(function () {
            // always executed
        });
        // 回到顶部
        window.addEventListener('scroll', this.handleScroll);
        // 滑动加载
        window.addEventListener('scroll', this.scrollFn);
    },
    methods: {
        // 回到顶部
         backTop(){
            let back = setInterval(() =>{
                 if(document.body.scrollTop || document.documentElement.scrollTop){
                    document.body.scrollTop -= 100;
                    document.documentElement.scrollTop -= 100;
                }else{
                    clearInterval(back)
                }
            });
        },
        handleScroll(){
             if (document.documentElement.scrollTop + document.body.scrollTop > 100) {
                 this.backTopShow = true;
            }else{
                 this.backTopShow = false;
            }
        },
        //文档高度
    　　getScrollTop(){
    　　var scrollTop = 0, bodyScrollTop = 0, documentScrollTop = 0;
    　　　　if(document.body){
    　　　　　　bodyScrollTop = document.body.scrollTop;
    　　　　}
    　　　　if(document.documentElement){
    　　　　　　documentScrollTop = document.documentElement.scrollTop;
    　　　　}
    　　　　scrollTop = (bodyScrollTop - documentScrollTop > 0) ? bodyScrollTop : documentScrollTop;
    　　　　return scrollTop;
    　　},
        // 可视窗口高度
        getWindowHeight(){
    　　var windowHeight = 0;
    　　　　if(document.compatMode == "CSS1Compat"){
    　　　　　　windowHeight = document.documentElement.clientHeight;
    　　　　}
    　　　　else{
    　　　　　　windowHeight = document.body.clientHeight;
    　　　　}
    　　　　return windowHeight;
    　　},
        //滚动条高度
        getScrollHeight(){
    　　　　var scrollHeight = 0, bodyScrollHeight = 0, documentScrollHeight = 0;
    　　　　if(document.body){
    　　　　　　bodyScrollHeight = document.body.scrollHeight;
    　　　　}　　
    　　　　if(document.documentElement){
    　　　　　　documentScrollHeight = document.documentElement.scrollHeight;
    　　　　}
    　　　　scrollHeight = (bodyScrollHeight - documentScrollHeight > 0) ? bodyScrollHeight : documentScrollHeight;
    　　　　return scrollHeight;
    　　},
        scrollFn(){
    　　　　if(this.getScrollTop() + this.getWindowHeight() == this.getScrollHeight()){
    　　　　　　//这里执行动态获取数据的函数
    　　　　}
    　　},
        // 销毁监听：
    　　destroyed() {
    　　　　window.removeEventListener('scroll', this.scrollFn); // 销毁监听
    　　}
    }
}
</script>

<style scoped>
   .index {
       width: 100%;
   }
    /* 分类部分 */
    .index .clasify{
        width: 100%;
        height: 26vh;
    }
    .index .clasify li{
        height: 55px;
        width: 55px;
        border-radius: 50%;
        margin: 10px 10px 16px 30px;
        position: relative;
    }
    .index .clasify li .icon{
        width: 30px;
        height: 30px;
        position: absolute;
        top: 12px;
        left: 12px;
    }
    .index .clasify li p{
        position: absolute;
        width: 17vw;
        height: 10px;
        top: 60px;
        left: 0;
        font-size: 14px;
        color: #666666;
    }
    /* 菜谱热搜榜 */ /* 时令与热门 */
    .index .hot {
        height: 50vh;
        border-bottom: 1px solid #f4f4f4;
    }
    .index .food,.index .hot{
        margin-top: 10px;
        width: 100%;
    }
    .index .food li,.index .hot li{
        width: 28%;
        height: 6.5vh;
        background: #f4f4f4;
        border-radius: 4px;
        margin-bottom: 15px;
    }
    .index .food li p,.index .hot li p{
        line-height: 6vh;
    }
    /* 最新食谱 */
    .index .title{
        color: #098bd6;
        margin-left: 10px;
        font-size: 18px;
    }
    .index .foods{
        margin-top: 10px;
        width: 100%;
        height: 90vh;
    }
    .index .foods li{
        width: 44%;
        height: 5vh;
    }
    .index .foods li img{
        width: 82%;
        height: 14vh;
        margin-left: 20px;
    }
    .index .foods li p,.index .food li p,.index .hot li p{
        font-size: 14px;
        text-align: center;
        color: #333333;
    }
    .index .head .tab li a,.index .hot li a,.index .reading li a,.foot a{
        text-decoration: none;
    }
    /* 推荐阅读 */
    .index .reading{
        margin-top: 10px;
        width: 100%;
    }
    .index .reading li:nth-of-type(1){
        border-top: 2px solid #e8e8e8;
    }
    .index .reading li{
        width: 100%;
        height: 9vh;
        border-top: 1px solid #e8e8e8;
        padding-top: 16px;
    }
    .index .reading li img{
        width: 22vw;
        height: 8vh;
        float: left;
    }
    .index .reading li h4{
        display: block;
        width: 73vw;
        height: 3vh;
        overflow: hidden;
        text-overflow:ellipsis;
        white-space: nowrap;
        font-size: 16px;
        color: #000000;
        float: right;
        padding-right: 10px;
    }
    .index .reading li p{
        color: #7b7b7b;
        font-size: 12px;
        float: left;
        width: 70vw;
        height: 12vh;
        padding-left: 10px;
        padding-top: 5px;
    }
    .index .reading li p span{
        float: right;
    }
    /* 底部 */
    .index .bottom{
        width: 100%;
        height: 6vh;
        background: #f5f5f5;
        border-top: 2px solid #e1e1e1;
        margin: 0px auto;
    }
    .index .bottom .wu{
        background: #eeeeee;
        width: 77%;
        line-height: 4vh;
        text-align: center;
        margin: 4px auto;
        font-size: 19px;
        color: #303030;
    }

</style>

<style>
    /* 轮播图 */
    .index .mint-swipe{
        height: 28vh;
    }
    .index .mint-swipe img{
        width: 100%;
    }
    .index .mint-swipe-item{
        position: relative;
    }
    .index .mint-swipe-item span{
        display: block;
        position: absolute;
        bottom: 0;
        right: 0;
        width: 100%;
        line-height: 30px;
        z-index: 2;
        color: #ffffff;
        font-size: 16px;
        margin-left: 20px;
        background: rgba(133, 133, 133, 0.4);
        margin-bottom: 5px;
    }
    .index .mint-swipe-item .fenshu{   
        display: block;     
        position: absolute;
        bottom: 0;
        right: -120px;
        width: 40%;
        height: 30px;
        opacity: 0.7;
    }
    .index .left{
        display: block;
        margin-left: 20px;
    }
</style>